<template>
  <div class="login-container">
    <form @submit.prevent="formSubmit">
      <h1>
        欢迎登录
        <span>智慧康复系统</span>
      </h1>
      <b>登录验证</b>
      <ul>
        <li>
          <input type="text" v-model="formData.account" placeholder="请输入用户名" />
        </li>
        <li>
          <input type="password" v-model="formData.password" placeholder="请输入密码" />
        </li>
      </ul>
      <input type="submit" class="submit" />
      <p class="tips">忘记密码？请联系管理员</p>
    </form>
    <div class="bg"></div>
    <img :src="require('../../assets/login-bg.png')" alt style="width:100%" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      formData: {
        account: "100200",
        password: "123456",
        openId: ""
      }
    };
  },
  methods: {
    formSubmit() {
      this.ajax("/api/User/Login/", "get", this.formData, false).then(res => {
        let response = res.data;
        if (response.code == 200) {
          window.localStorage.token = response.data.token;
          if (response.data.userInfo && response.data.userInfo[0]) {
            var item = response.data.userInfo[0];
            window.localStorage.UserId = item.Id;
            window.localStorage.Nickname = item.Nickname;
            window.localStorage.Account = item.Account;
          }
        }
        this.$Message.info(response.msg);
      });
    }
  }
};
</script>

<style scope lang="less">
.tips {
  text-align: center;
  margin-top: 25px;
  color: #666;
  font-size: 14px;
}
.login-container {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  form {
    width: 400px;
    height: 500px;
    padding: 50px;
    box-sizing: border-box;
    border-radius: 10px;
    background: #ffffff;
    position: absolute;
    z-index: 9;
    top: 50%;
    left: 50%;
    margin-top: -250px;
    margin-left: -200px;
    z-index: 11;
    h1 {
      font-size: 18px;
      color: #666;
      font-weight: normal;
      text-align: center;
      span {
        color: #2178ff;
      }
    }
    b {
      display: block;
      text-align: center;
      margin-top: 30px;
      margin-bottom: 60px;
      font-size: 14px;
      color: #999;
      font-weight: normal;
      position: relative;
      &::before {
        content: "";
        position: absolute;
        left: 50%;
        bottom: -10px;
        margin-left: -10px;
        width: 20px;
        height: 2px;
        background: #277bff;
      }
    }

    ul {
      width: 300px;
      height: 100px;
      border-radius: 5px;
      border: 1px solid #ddd;
      overflow: hidden;
      margin-bottom: 50px;
      li {
        list-style: none;
        height: 50%;
        &:first-child input {
          border-bottom: 1px solid #ddd;
        }
        input {
          padding: 0 10px;
          font-size: 14px;
          width: 100%;
          height: 100%;
          border: 0;
          outline: none;
        }
      }
    }
  }
  .submit {
    width: 100%;
    height: 50px;
    background: linear-gradient(
      90deg,
      rgba(84, 151, 255, 1) 0%,
      rgba(33, 120, 255, 1) 100%
    );
    box-shadow: 0px 3px 6px rgba(97, 148, 236, 0.44);
    border-radius: 5px;
    border: 0;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    outline: none;
    &:active {
      transform: scale(0.99, 0.99);
    }
  }
  .bg {
    z-index: 10;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(35, 121, 255, 0.2);
  }
  & > img {
    z-index: 9;
    position: absolute;
    top: 0;
    left: 0;
  }
}
</style>
